from typing import Optional, List

from sqlalchemy import Integer, JSON, BIGINT
from sqlmodel import Field

from src.base.beans import PageParam
from src.base.enums import DataScopeType
from src.domain.base_model import TenantModel
from src.base.beans import Bigint


class SysRoleBase(TenantModel):
    role_id: Optional[Bigint] = Field(default=None, primary_key=True, description="角色序号", sa_type=BIGINT,
                                      sa_column_kwargs={"comment": "角色序号"})
    role_name: Optional[str] = Field(default=None, description="角色名称", sa_column_kwargs={"comment": "角色名称"})
    role_code: Optional[str] = Field(default=None, description="角色编码", sa_column_kwargs={"comment": "角色编码"})
    data_scope: Optional[DataScopeType] = Field(default=None, description="数据权限范围", sa_type=Integer,
                                                sa_column_kwargs={"comment": "数据权限范围", "server_default": "5"})
    custom_dept_ids: Optional[List[Bigint]] = Field(default=None, description="自定义部门权限", sa_type=JSON, )
    custom_user_ids: Optional[List[Bigint]] = Field(default=None, description="自定义用户权限", sa_type=JSON, )


class SysRole(SysRoleBase, table=True):
    __tablename__ = "sys_role"
    __table_args__ = {'extend_existing': True, 'comment': '角色表'}


class SysRoleReq(SysRoleBase, PageParam):
    menu_ids: Optional[List[Bigint]] = Field(default=None, description="菜单id")
    create_time_range: Optional[list[str]] = Field(default=None, description="创建时间范围")
    update_time_range: Optional[list[str]] = Field(default=None, description="更新时间范围")


class SysRoleResp(SysRoleBase):
    menu_ids: Optional[List[Bigint]] = Field(default=None, description="菜单id")
